<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul{
            list-style: none;
        }
    </style>
</head>
<body>
    <h1>请选择于谦的爱好</h1>
    <ul>
        <li><input type="checkbox" name="like" id="" value="">抽烟</li>
        <li><input type="checkbox" name="like" id="" value="">喝酒</li>
        <li><input type="checkbox" name="like" id="" value="">烫头</li>
        <li><input type="checkbox" name="like" id="" value="">说相声</li>
    </ul>
    <button onclick="select(true)">全选</button>
    <button onclick="select(false)">不选</button>
    <button>反选</button>



    <script>
        var like = document.getElementsByName('like');
        var btns = document.querySelectorAll('button');
        function select(bool){
            for(var i=0;i<like.length;i++){
                like[i].checked = bool;
            }
        }
        btns[2].onclick=function(){
            for(var i=0;i<like.length;i++){
                if(like[i].checked === true){
                    like[i].checked = false;
                }else{
                    like[i].checked = true;
                }
            }
        }
    </script>

</body>
</html>